from selenium.webdriver.common.by import By
from base.base import Base
import json
from selenium.webdriver.common.action_chains import ActionChains

class PageUserlist(Base):

    system_bt_locator = (By.XPATH, '//span[text()="系统管理"]')
    userlist_bt_locator = (By.XPATH,'//span[text()="用户列表"]')
    #搜索框
    search_username_locator = (By.XPATH,'(//input[@class="ant-input"])[1]')
    search_name_locator = (By.XPATH,'(//input[@class="ant-input"])[2]')
    search_btn_locator = (By.XPATH,'//span[text()="查 询"]')
    userlist_locator = (By.XPATH,'//tbody//td[contains(@class,"ant-table-cell")]')
    #所属公司
    company_locator = (By.XPATH,'//table//a')
    input_company_locator = (By.XPATH,'//input[@placeholder="请输入公司名称"]')
    #确认按钮
    confirm_btn_locator = (By.XPATH,'//span[text()="确 定"]')

    def page_jump(self):
        ActionChains(self.driver).move_to_element(self.find(self.system_bt_locator)).perform()
        ActionChains(self.driver).click(self.find(self.userlist_bt_locator)).perform()
    #用户名输入
    def input_username(self):
        self.input(self.search_username_locator,'xiaoqing')
    #姓名输入
    def input_name(self):
        self.input(self.search_name_locator,'xq1')
    #点击查询
    def click_searchbt(self):
        self.click(self.search_btn_locator)

    #获取用户列表
    def get_userlist(self):
        values = []
        data_list = self.finds(self.userlist_locator)
        for elm in data_list:
            values.append(elm.text)
        return values

    #设置所属公司
    def set_company(self,name):
        self.click(self.company_locator)
        self.clear(self.input_company_locator)
        self.input(self.input_company_locator,name)
        self.click(self.confirm_btn_locator)
